
<script lang="ts">
import { useUser } from '@/store';
interface I_Router {
    description: string;
    icon: string;
    id: number;
    name: string;
    pagePath: string;
    path: string;
    pid: number;
    sortNum: number;
    children: I_Router[];
};
interface I_State {
    menuList: I_Router[];
}
export default defineComponent({
    setup() {
        const userStore = useUser();
        const router = useRouter();
        const { user } = storeToRefs(userStore);
        const state = reactive<I_State>({
            menuList: [...user.value.menus]
        });
        const exitLogin = () => {
            userStore.user = {
                role: "",
                token: "",
                id: 0,
                uid: '',
                name: '',
                password: '',
                menus: []
            };
            window.sessionStorage.clear();
            router.replace('/login');
        };
        const toPerson = () => {
            router.push('about');
        };
        return {
            user,
            exitLogin,
            toPerson,
            ...toRefs(state)
        };
    },
});
</script>
<template>
    <div class="con_warpper">
        <el-container>
            <el-header>
                <div>
                    <div class="header_img">
                        <img src="@/assets/logo.png" alt="图片加载失败" title="个人中心" @click="toPerson()" />
                    </div>
                    <span>web成绩管理系统</span>
                </div>
                <el-button type="info" @click="exitLogin">退出</el-button>
            </el-header>
            <el-container class="body">
                <el-aside width="200px">
                    <el-menu default-active="welcome" class="el-menu-vertical-demo" :collapse-transition="false"
                        :router="true">
                        <template v-for="item in menuList">
                            <el-sub-menu :index="(item.path || item.name).slice(1)" v-if="item.children.length">
                                <template #title>
                                    <i :class="item.icon" style="margin-right:2px;"></i>
                                    <span>{{ item.name }}</span>
                                </template>
                                <el-menu-item :index="item2.path.slice(1)" v-for="item2 in item.children">
                                    <template #title>
                                        <i :class="item2.icon" style="margin-right:2px;"></i>
                                        <span>{{ item2.name }}</span>
                                    </template>
                                </el-menu-item>
                            </el-sub-menu>
                            <el-menu-item :index="item.path.slice(1)" v-if="(item.children.length === 0)">
                                <template #title>
                                    <i :class="item.icon" style="margin-right:2px;"></i>
                                    <span>{{ item.name }}</span>
                                </template>
                            </el-menu-item>
                        </template>
                    </el-menu>
                </el-aside>
                <el-main>
                    <router-view></router-view>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>
<style lang = "less" >
.con_warpper {
    height: 100%;
    position: relative;
    width: 100%;
    display: flex;
    justify-content: flex-start;

    .el-header {
        padding-left: 0;
        background-color: #62777d;
        display: flex;
        justify-content: space-between;
        align-items: center;
        color: #fff;
        font-size: 20px;
        padding: 0 20px 0px 0px;
        box-sizing: border-box;

        div {
            display: flex;
            align-items: center;

            .header_img {
                margin-left: 20px;
                width: 50px;
                height: 50px;
                border-radius: 50%;
                border: 2px solid #63aac0;

                img {
                    border-radius: 50%;
                    width: 100%;
                    height: 100%;
                    transform: scale(0.8);

                    &:hover {
                        cursor: pointer;
                        transform: scale(1.1);
                        transition: transform 0.7s;
                        border: 2px solid #08bef5;
                    }
                }
            }

            span {
                margin-left: 15px;
            }
        }
    }

}

.body {
    .el-aside {
        background-color: #62777d;

        .toggle-button {
            width: 100%;
            height: 30px;
            background-color: #62777d;
            font-size: 10px;
            line-height: 30px;
            color: rgb(2, 2, 2);
            text-align: center;
            letter-spacing: 0.2em;
            cursor: pointer;
        }

        .el-menu {
            border-right: none;
        }
    }

    .el-main {
        // background-color: rgba(0, 0, 0, 0.15) !important;
        overflow-x: hidden;
        position: relative;
        padding: 10px;
        box-sizing: border-box;
    }
}
</style>